<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">名称</label>
        <el-input v-model="query.studentName" clearable placeholder="名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">年龄</label>
        <el-input v-model="query.age" clearable placeholder="年龄" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">性别</label>
        <el-input v-model="query.grade" clearable placeholder="性别" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="主键">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="名称" prop="studentName">
            <el-input v-model="form.studentName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="年龄">
            <el-input v-model="form.age" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="性别">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-date-picker v-model="form.updateDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建人">
            <el-input v-model="form.createUser" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新人">
            <el-input v-model="form.updateUser" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="格式化">
            <el-input v-model="form.format1" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="主键" />
        <el-table-column prop="studentName" label="名称" />
        <el-table-column prop="age" label="年龄" />
        <el-table-column prop="grade" label="性别" />
        <el-table-column prop="createDate" label="创建时间" :formatter="dateFormat"  >
<!--          <template slot-scope="scope">-->
<!--            <span>{{ scope.row.createDate }}</span>-->
<!--          </template>-->
        </el-table-column>
        <el-table-column prop="updateDate" label="更新时间" :formatter="dateFormat">

        </el-table-column>
        <el-table-column prop="createUser" label="创建人" />
        <el-table-column prop="updateUser" label="更新人" />
        <el-table-column prop="format1" label="格式化" />
        <el-table-column v-permission="['admin','outputTest:edit','outputTest:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudOutputTest from '@/api/system/outputTest'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import moment from 'moment'

const defaultForm = { id: null, studentName: null, age: null, grade: null, createDate: null, updateDate: null, createUser: null, updateUser: null, format1: null }
export default {
  name: 'OutputTest',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'output', url: 'api/outputTest', sort: 'id,desc', crudMethod: { ...crudOutputTest }})
  },
  methods: {
    //时间格式化
    dateFormat:function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("yyyy/MM/DD HH:mm:ss");
    } ,
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  },
  data() {
    return {
      permission: {
        add: ['admin', 'outputTest:add'],
        edit: ['admin', 'outputTest:edit'],
        del: ['admin', 'outputTest:del']
      },
      rules: {
        studentName: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'studentName', display_name: '名称' },
        { key: 'age', display_name: '年龄' },
        { key: 'grade', display_name: '性别' }
      ]
    }
  },

}
</script>

<style scoped>

</style>
